package action;

import java.io.IOException;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import dao.impl.MeetingDAOImpl;
import bean.Meeting;

public class SearchAction extends HttpServlet {
	private MeetingDAOImpl md = new MeetingDAOImpl();

	public void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		doPost(request, response);
	}

	public void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		String page = "meeting_list.jsp";
		request.setCharacterEncoding("utf-8");
		// 获取数据
		String topic = request.getParameter("meetingTopic");
		String meetingDate = request.getParameter("meetingDate");
		String participants = request.getParameter("meetingParticipants");
		String meetingType = request.getParameter("meetingType");
		// 封装条件数据
		Meeting condition = new Meeting();
		if (!"".equals(topic)) {
			condition.setTopic(topic);
		}
		if (!"".equals(meetingDate)) {
			// condition.setMeetingdate(new Date(meetingDate));
		}
		if (!"".equals(participants)) {
			condition.setParticipants(participants);
		}
		if (!"".equals(meetingType)) {
			condition.setType(meetingType);
		}
		request.setAttribute("listData", md.search(condition, Meeting.class));
		RequestDispatcher rd = request.getRequestDispatcher(page);
		rd.forward(request, response);
	}

}
